<?php

header("Content-type:text/html;charset=utf8");//字符编码设置

error_reporting(0);

$nid = $_POST['nid'];
$title = $_POST['title'];
$stutext = $_POST['stutext'];



if($nid!=NULL && $title!=NULL && $stutext!=NULL){
    $conn = mysqli_connect('localhost:3306','root','124938');
    mysqli_select_db($conn,'schedule');
    mysqli_query($conn,'SET NAMES UTF8');

    $sql = " select * from note where nid='$nid'";
    $res = mysqli_query($conn,$sql);
    $row=mysqli_fetch_array($res);
    if (mysqli_num_rows($res) >= 1){
        echo "<script>alert('笔记已存在')</script>";
    }
    else {
        $sql = " insert into note (nid,title,stutext) values('$nid','$title','$stutext')";

        if ($conn->query($sql) == TRUE) {
            echo "<script>alert('插入成功')</script>";
        } else {
            echo "Error: " . $sql . "<br>" . $conn->error;
        }
        $conn->close();
    }
    ?>
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title>学生笔记</title>
        <link rel="stylesheet" href="style.css" />
        <style>
            body {
                background-image: url(images/background1.png);
                background-repeat: no-repeat;
                background-position: center top;
                background-size: cover;
            }
        </style>
    </head>


    <body>
        <div class="header w">
            <div class="logo">
                <img src="images/logo.png" alt="" />
            </div>

            <div class="nav">
                <ul>
                    <li><a href="index.html" target="_self">学生课表</a></li>
                    <li><a href="classroom.html" target="_self">教室课表查询</a></li>
                    <li><a href="teacher.html" target="_self">教师课表查询</a></li>
                    <li><a href="stunotes.html" target="_self">学生笔记</a></li>
                    <li><a href="notice.html" target="_self">通知公告</a></li>
                </ul>
            </div>
        </div>

        <div class="header w">
        <?php

        echo "<table border=6 frame = void align = center width = 1200px height = 100px cellspacing = 0px cellpadding = 10 px>";
        echo "  <tr height = 40px align = center>
                     <td ></td><td colspan = 4 color = red><font color = \"red\"><b>学生笔记</b></font></td>
                </tr>";
        echo "  <tr height = 50px align = center>
                     <th width = 110px></th><th><font color = blue>笔记标识</font></th><th><font color = blue>笔记标题</font></th><th><font color = blue>笔记内容</font></th>
                </tr>";


        $conn = mysqli_connect('localhost:3306','root','124938');
        mysqli_select_db($conn,'schedule');
        mysqli_query($conn,'SET NAMES UTF8');

        $sql = " select * from note";
        $res = mysqli_query($conn,$sql);
//        $row=mysqli_fetch_array($res);
        $i=1;
        while($row=@mysqli_fetch_array($res)){
            echo "<tr height = 100px align = center>";

            for ($j = 0; $j < 4; $j++) {
                if($j == 0){
                    echo "<td>$i<br></td>";
                }
                else if($j == 1){
                    echo "<td>$row[0]<br></td>";
                }
                else if($j == 2){
                    echo "<td>$row[1]<br></td>";
                }
                else{
                    echo "<td>$row[2]<br></td>";
                }
            }
            echo "</tr>";
            $i++;
        }

        echo "</table>";
        ?>
        </div>
    </body>
    </html>
<?php
}
else{
    echo "<script>alert('输入格式错误！！')</script>";
    quit;
}
?>

<?php
    echo "<script>alert('当前笔记显示！！')</script>";
?>